#include "widget.h"
#include "ui_widget.h"
#include <QDateTime>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{
    //获取到两个时间框的时间日期
    QDateTime timeOld = ui->dateTimeEdit_old->dateTime();
    QDateTime timeNew = ui->dateTimeEdit_new->dateTime();

    //计算日期差值
    int days = timeOld.daysTo(timeNew);
    int seconds = timeOld.secsTo(timeNew);
    int hours = (seconds/ 3600) % 24;

    //设置 label 的内容
    QString text = QString("爱你已经持续了 ") + QString::number(days) + QString("天零")
                   + QString::number(hours) + QString(" 个小时！");

    ui->label->setText(text);
}

